<%include file="header.html"%>
<%include file="top.html"%>
<%include file="left.html"%>

<style>

body,h1,p,blockquote,dl,dt,dd,ul,ol,li,input{margin:0;padding:0;} 
.autoDis{border:1px solid #999;position:absolute;overflow:hidden;} 
.autoDis p{line-height:25px;cursor:default;padding:0 5px;} 
.autoDis li{line-height:25px;cursor:default;padding:0 5px;background-color:#fff;} 
.autoDis .cur{background:#ccc;} 

input[type=checkbox].ace, input[type=radio].ace {
opacity: 0;
position: absolute;
z-index: 12;
width: 18px;
height: 38px;
cursor: pointer;
}

.table-header {
background-color: #307ecc;
color: #FFF;
font-size: 14px;
line-height: 35px;
padding-left: 12px;
margin-bottom: 1px;
padding-bottom:2px;
}

input[type=checkbox].ace+.lbl, input[type=radio].ace+.lbl {
  position: relative;
  z-index: 0;
  display: inline-block;
  margin: 0;
  line-height: 20px;
  min-height: 18px;
  min-width: 18px;
  font-weight: normal;
}

.comments {  
 width:100%;/*自动适应父布局宽度*/  
 overflow:auto;  
 word-break:break-all; 
 border-color:#307ecc;
 float:left;
 }
 
</style>
<div class="main-content">
<div class="breadcrumbs" id="breadcrumbs"><script
	type="text/javascript">
	try {
		ace.settings.check('breadcrumbs', 'fixed')
	} catch (e) {
	}
</script>

<ul class="breadcrumb">
	<li><i class="icon-home home-icon"></i> <a
		href="index.php">首页</a></li>
</ul>
<!-- .breadcrumb --></div>

<div class="page-content">
<div id="top1" class="col-xs-12">
<div class="alert alert-info">
<form class="form-horizontal" role="form">
<div class="row">

<div class="col-sm-2">
<div class="row">
<label class="col-sm-6 control-label no-padding-right" for="form-field-5">游戏</label>
<div class="col-sm-3"><select id="selectGame">
	<option value="" >游戏</option>
	<%if $selectGames%> <%foreach from = $selectGames key = key item = value%>
	<%if $nowGame == $value %>
	<option value="<%$value%>" selected><%$value%></option>
	<%else%>
	<option value="<%$value%>"><%$value%></option>
	<%/if%> <%/foreach%> <%/if%>
</select>
</div>
</div>
</div>



<div class="col-sm-2">
<div class="row">
<label class="col-sm-3 control-label no-padding-right" for="form-field-5">平台</label>
<div class="col-sm-3">
<select id="platform">
	<option value="" id="selectPlatform">平台</option>
	
	<%if $platforms%> <%foreach from = $platforms key = key item = value%>
	<%if $platform == $value %>
	<option value="<%$value%>" selected><%$value%></option>
	<%else%>
	<option value="<%$value%>"><%$value%></option>
	<%/if%> <%/foreach%> <%/if%>
	
</select>
</div>
</div>
</div>



<div class="col-sm-3">
<div class="row">
<label class="col-sm-2 control-label no-padding-right" for="form-field-5">超时(s)</label>
<div class="col-sm-9">
<input type="text" id="timeout" class="col-xs-6 col-sm-5" value ="<%$timeout%>">
</div>
</div>
</div>



<div class="col-sm-2">
<div class="row"><label
	class="col-sm-3 control-label no-padding-right" for="form-field-5">&nbsp;&nbsp;&nbsp;&nbsp;</label>
<div class="col-sm-9">
</div>
</div>
</div>

</div>
</form>
</div>
</div>


<div id="top2" class="col-xs-12">
<div class="table-header"> 
<div class="col-sm-1">
<div class="row">
<div class="col-sm-1">
<select style="margin-left:0px;margin-top:5px;width:120px;" id="shelloperation">
	<option value="" id="operationType">操作类型 </option>
	<%if $shelloperation%> <%foreach from = $shelloperation key = key item = operation%>
	<%if $shelloperationType == $operation.shell %>
	<option value="<%$operation.shell%>" selected><%$operation.name%></option>
	<%else%>
	<option value="<%$operation.shell%>"><%$operation.name%></option>
	<%/if%> <%/foreach%> <%/if%>
</select>

</div>
</div>
</div>
&nbsp;&nbsp;
<button class="btn btn-primary" type="button" onClick="formSubmit();">执行任务</button>

&nbsp;&nbsp;&nbsp;&nbsp;
<button class="btn btn-primary" type="button" onClick="updateUrl();">updateXml</button>


&nbsp;&nbsp;&nbsp;&nbsp;
<button class="btn btn-primary" type="button" onClick="updateUrlJar();">updateJar</button>
<!-- 
<button class="btn btn-primary" type="button" onClick="formSubmitXML();">更新XML</button> 查看时间 date | 修改日期 date -s "<%$nowTime%>" |  修改时间 date -s "<%$Time%>" 
 -->
</div>
</div>
<form class="form-horizontal" role="form">
<label class="col-sm-3 control-label no-padding-right" for="form-field-5"></label>
<div class="col-sm-12">
<input style="border-color:#307ecc;" id="command" type="text" id="timeout" class="col-xs-12 col-sm-12" value="<%$args%><%$tipsValue%>" placeholder="<%$tips%>" >
<!--  
<textarea  id="command" class="comments" rows=1   name=s1   cols=50   onpropertychange= "this.style.posHeight=this.scrollHeight" >
<%$content%>
</textarea>
-->
</div>

<!--  
<label class="col-sm-3 control-label no-padding-right" for="form-field-5"></label>
<label class="col-sm-3 control-label no-padding-right" for="form-field-5"></label>

<center>
<div class="col-sm-12">
<button type="button" onClick="formSubmit();"
	class="width-10 btn btn-sm btn-primary"><h5>执行</h5></button>
</div>
</center>
-->

</form>

<div class="col-xs-12">
<label class="col-sm-3 control-label no-padding-right" for="form-field-5"></label>
</div>


<div  class="col-xs-12">
<div  id ="servers2" class="table-header">
服务器列表
<%if $selectAll%>
			<input style="padding-botton:10px;;"   name="checkbox3" type="checkbox" class="ace ace-checkbox-2" id="selectAll"   value="selectAll" /> 
			<label style="width:80px;" class="lbl" for="ace-settings-navbar">&nbsp;全选</label>
<%/if%>
<%if $selectNo%>
			<input  name="checkboxs2" type="checkbox" class="ace ace-checkbox-2" id="unSelect"   value="unSelect" />
			<label style="width:80px;" class="lbl" for="ace-settings-navbar">&nbsp;全不选</label>
<%/if%>
</div>

<!-- style="width:100%;height:650px;overflow-x:auto;overflow-y:auto;" -->
<div  id="servers"  class="table-responsive">
<table id="sample-table-1"
	class="table table-striped table-bordered table-hover">
	<thead>
		<tr>
			<th>
				服务器
			</th>
			<th>主机地址</th>
			<th>db地址</th>
			<th>运行目录</th>
			<th>执行结果</th>
			<th>状态</th>
		</tr>
	</thead>
	<tbody>
	
		
		<%foreach from=$servers item=servers%>
		<tr>
			<td   style="padding-top:20px;"><input  name="checkboxs" type="checkbox" class="ace ace-checkbox-2" id="<%$servers.game%>" <%if $servers.type == 0%> disabled="true" <%/if%>   <%if $servers.isView == 1%> checked<%/if%> value = "<%$servers.name%>" />
				<label style="width:120px;" class="lbl" for="ace-settings-navbar">&nbsp;<%$servers.name%></label>
			</td>
			<td  style="padding-top:20px;"><%$servers.ip%>:<%$servers.scriptPort%></td>
			<td  style="padding-top:20px;"><%$servers.dburl%></td>	
			<td  style="padding-top:20px;"><%$servers.folder%></td>	
			<td style="width:60%;">
			     <!-- onpropertychange= "this.style.posHeight=this.style.posHeight" -->
				 <textarea  class="comments" rows=1   name=s1   cols=50  onmouseover= "textCount(this,3);" onmouseout = "textCount(this,1)"  ><%$servers.res%>
		    	 </textarea>
			</td>
			<td align="center"  style="width:5%;padding-top:20px;"><%$servers.status%></td>
		</tr>
		<%/foreach%>

	</tbody>
</table>
</div>
</div>


</div>
<!-- /.page-content --></div>
<!-- /.main-content -->
<script type="text/javascript">
	
function textCount(obj, value) {
	obj.rows  = value;
}	
	
//全选
$("#selectAll").click(function(){
	 $("#servers :checkbox").prop("checked", true); 
}); 
// 反选
$("#unSelect").click(function () {//全不选  
     $("#servers :checkbox").prop("checked", false); 
});  	
	
	jQuery(function($) {
		$('.date-picker').datepicker({
			autoclose : true
		}).next().on(ace.click_event, function() {
			$(this).prev().focus();
		});

		var oTable1 = $('#sample-table-2').dataTable({
			"aoColumns" : [ {
				"bSortable" : false
			}, {
				"bSortable" : false
			}, {
				"bSortable" : false
			}
			]
		});
		

	});

	function formSubmit() {
		var game = $('#selectGame').val();
		var platform = $('#platform').val();
		var shelloperation = $('#shelloperation').val();
		
		var timeout = $('#timeout').val();
		var args = $('#command').val();
		
		var servers=''; 
		$("input[name='checkboxs']:checked").each(function(){
			if(servers == '') {
				servers = $(this).val();
			} else {
				servers += ',' + $(this).val(); 
			}
			
		});
		
		if(!game) {
			alert("请选择游戏");
			return ;
		}
		if(!servers) {
			alert("请选择服");
			return ;
		}
		if(!shelloperation) {
			alert("请选择操作类型");
			return ;
		}
		
		url = "index.php?mod=Shell&do=operation&game="+game+"&platform="+platform+"&servers="+servers+"&args="+args+"&timeout="+timeout+"&shelloperation="+shelloperation+"&type=exec";
		window.location.href = url;

	}
	
	/**
	连接新地址
	*/
	function updateUrl() {
		var game = $('#selectGame').val();
		if(!game) {
			alert("请选择游戏");
			return ;
		}
		window.open("<%$updateUrl%>");
	}
	
	/**
	连接新地址
	*/
	function updateUrlJar() {
		var game = $('#selectGame').val();
		if(!game) {
			alert("请选择游戏");
			return ;
		}
		window.open("<%$updateUrlJar%>");
	}
	/*
	更新xml
	*/
	function formSubmitXML() {
		var game = $('#selectGame').val();
		var platform = $('#platform').val();
		var timeout = $('#timeout').val();
		
		var command = "sh /data/java/shell/upXml_" + game + ".sh";
		
		var servers=''; 
		$("input[name='checkboxs']:checked").each(function(){ 
			servers += $(this).val()+','; 
		});
		
		if  (!timeout || !servers) {
			alert('请选择服！');
		} else {
			url = "index.php?mod=Shell&do=operation&game="+game+"&platform="+platform+"&servers="+servers+"&command="+command+"&timeout="+timeout;
			window.location.href = url;
		}

	}
	
	
	window.onload = function(){
	    var select = document.getElementById('selectGame');
	    select.onchange = function(){
	       var game = $('#selectGame').val();
	        var platform = $('#platform').val();
	        var shell = $('#shelloperation').val();
	        var timeout = $('#timeout').val();
			url = "index.php?mod=Shell&do=operation&game="+game+"&platform="+platform+"&shelloperation="+shell+"&timeout="+timeout;
			window.location.href = url;  

	    }
	    // 选择平台
	    var selectPlatform = document.getElementById('platform');
	    selectPlatform.onchange = function(){
	        var game = $('#selectGame').val();
	        var platform = $('#platform').val();
	        var shell = $('#shelloperation').val();
	        var timeout = $('#timeout').val();
	    	var servers=''; 
			$("input[name='checkboxs']:checked").each(function(){
				if(servers == '') {
					servers = $(this).val();
				} else {
					servers += ',' + $(this).val(); 
				}
				
			});
			url = "index.php?mod=Shell&do=operation&game="+game+"&platform="+platform+"&shelloperation="+shell+"&servers="+servers+"&timeout="+timeout;
			window.location.href = url;  
	    }
	    
	    // 选择类型
	    var shelloperation = document.getElementById('shelloperation');
	    shelloperation.onchange = function(){
	        // 更改值后执行的代码
	        var game = $('#selectGame').val();
	        var platform = $('#platform').val();
	        var shell = $('#shelloperation').val();
	        var timeout = $('#timeout').val();
	    	var servers=''; 
			$("input[name='checkboxs']:checked").each(function(){
				if(servers == '') {
					servers = $(this).val();
				} else {
					servers += ',' + $(this).val(); 
				}
				
			});
			
			url = "index.php?mod=Shell&do=operation&game="+game+"&platform="+platform+"&shelloperation="+shell+"&servers="+servers+"&timeout="+timeout;
			window.location.href = url;  
	    }
	    
	} 
	
</script>


<script type="text/javascript"> 

<%if $shells %>

(autoComplete={ 
pop_len:10, 
pop_cn:'autoDis', 
hover_cn:'cur', 
source:'<%$shells%>'.split('|'),
init:function(){ 
this.setDom(); 
return this; 
}, 
bind:function(x){ 
if(x.getAttribute('type') != 'text' || x.nodeName != 'INPUT') 
return null; 
var self = this; 
x.onkeyup = function(e){ 
e = e || window.event; 
var lis = self.pop.getElementsByTagName('li'),lens = self.pop.getElementsByTagName('li').length,n=lens,temp; 
if(e.keyCode == 38){ //键盘up键被按下 
if(self.pop.style.display != 'none'){ 
for(var i=0;i<lens;i++){ //遍历结果数据，判断是否被选中 
if(lis[i].className) 
temp = i; 
else 
n--; 
} 
if(n==0){ //如果没有被选中的li元素，则选中最后一个 
lis[lens-1].className = self.hover_cn; 
this.value = lis[lens-1].innerHTML; 
}else{ //如果有被选中的元素，则选择上一个元素并赋值给input 
if(lis[temp] == lis[0]){ //如果选中的元素是第一个孩子节点则跳到最后一个选中 
lis[lens-1].className = self.hover_cn; 
this.value = lis[lens-1].innerHTML; 
lis[temp].className = ''; 
}else{ 
lis[temp-1].className = self.hover_cn; 
this.value = lis[temp-1].innerHTML; 
lis[temp].className = ''; 
} 
} 
}else //如果弹出层没有显示则执行插入操作，并显示弹出层 
self.insert(this); 
}else if(e.keyCode == 40){ //down键被按下，原理同up键 
if(self.pop.style.display != 'none'){ 
for(var i=0;i<lens;i++){ 
if(lis[i].className) 
temp = i; 
else 
n--; 
} 
if(n==0){ 
lis[0].className = self.hover_cn; 
this.value = lis[0].innerHTML; 
}else{ 
if(lis[temp] == lis[lens-1]){ 
lis[0].className = self.hover_cn; 
this.value = lis[0].innerHTML; 
lis[temp].className = ''; 
}else{ 
lis[temp+1].className = self.hover_cn; 
this.value = lis[temp+1].innerHTML; 
lis[temp].className = ''; 
} 
} 
}else 
self.insert(this); 
}else //如果按下的键既不是up又不是down那么直接去匹配数据并插入 
self.insert(this); 
}; 
x.onblur = function(){ //这个延迟处理是因为如果失去焦点的时候是点击选中数据的时候会发现先无法触发点击事件 
setTimeout(function(){self.pop.style.display='none';},300); 
}; 
return this; 
}, 
setDom:function(){ 
var self = this; 
var dom = document.createElement('div'),frame=document.createElement('iframe'),ul=document.createElement('ul'); 
document.body.appendChild(dom); 
with(frame){ //用来在ie6下遮住select元素 
setAttribute('frameborder','0'); 
setAttribute('scrolling','no'); 
style.cssText='z-index:-1;position:absolute;left:0;top:0;' 
} 
with(dom){ //对弹出层li元素绑定onmouseover，onmouseover 
className = this.pop_cn; 
appendChild(frame); 
appendChild(ul); 
onmouseover = function(e){ //在li元素还没有加载的时候就绑定这个方法，通过判断target是否是li元素进行处理 
e = e || window.event; 
var target = e.srcElement || e.target; 
if(target.tagName == 'LI'){ //添加样式前先把所有的li样式去掉，这里用的是一种偷懒的方式，没有单独写removeClass方法 
for(var i=0,lis=self.pop.getElementsByTagName('li');i<lis.length;i++) 
lis[i].className = ''; 
target.className=self.hover_cn; //也没有写addClass方法，直接赋值了 
} 
}; 
onmouseout = function(e){ 
e = e || window.event; 
var target = e.srcElement || e.target; 
if(target.tagName == 'LI') 
target.className=''; 
}; 
} 
this.pop = dom; 
}, 
insert:function(self){ 
var bak = [],s,li=[],left=0,top=0,val=self.value; 
for(var i=0,leng=this.source.length;i<leng;i++){ //判断input的数据是否与数据源里的数据一致 
if(!!val&&val.length<=this.source[i].length&& this.source[i].substr(0,val.length) == val){ 
bak.push(this.source[i]); 
} 
} 
if(bak.length == 0){ //如果没有匹配的数据则隐藏弹出层 

	/*
	this.pop.style.display='none'; 
	return false; 
	*/
	// 没有匹配的所有都列出来
	for(var i=0,leng=this.source.length;i<leng;i++){ //判断input的数据是否与数据源里的数据一致 
		bak.push(this.source[i]); 
	}
	
}//这个弹出层定位方法之前也是用循环offsetParent，但发现ie跟ff下差别很大（可能是使用方式不当），所以改用这个getBoundingClientRect 
left=self.getBoundingClientRect().left+document.documentElement.scrollLeft; 
top=self.getBoundingClientRect().top+document.documentElement.scrollTop+self.offsetHeight; 
with(this.pop){ 
style.cssText = 'width:'+self.offsetWidth+'px;'+'position:absolute;left:'+left+'px;top:'+top+'px;display:none;'; 
getElementsByTagName('iframe')[0].setAttribute('width',self.offsetWidth); 
getElementsByTagName('iframe')[0].setAttribute('height',self.offsetHeight); 
onclick = function(e){ 
e = e || window.event; 
var target = e.srcElement || e.target; 
if(target.tagName == 'LI') 
self.value = target.innerHTML; 
this.style.display='none'; 
}; 
} 
s = bak.length>this.pop_len?this.pop_len:bak.length; 
for(var i=0;i<s;i++) 
li.push( '<li>' + bak[i] +'</li>'); 
this.pop.getElementsByTagName('ul')[0].innerHTML = li.join(''); 
this.pop.style.display='block'; 
} 
}).init().bind( document.getElementById('command')); 

<%/if%>

</script> 

<%include file="footer.html"%>

